import { _decorator,Component ,Node } from 'cc';
import { Core } from '../Core/Core';
import { EView } from '../Config/Enum';


const { ccclass, property } = _decorator;

@ccclass('ChooseBox')
export class ChooseBox extends Component {



    ndBG: Node = null!; // 背景节点
    ndParent: Node = null!; // 父节点



    protected onLoad(): void {
        this.ndBG = this.node.getChildByName("BG");
        this.ndParent = this.node.parent;

        

        

        
    }

    protected onEnable(): void {
        //this.ndBG.on(Node.EventType.TOUCH_END, this.onButtonCloseWindow, this);
        this.node.on(Node.EventType.TOUCH_END, this.onBtnOpenChooseDetail, this);

        
    }

    protected onDisable(): void {

        //this.ndBG.off(Node.EventType.TOUCH_END, this.onButtonCloseWindow, this);
        this.node.off(Node.EventType.TOUCH_END, this.onBtnOpenChooseDetail, this);
        
    }

    protected start(): void {
        
    }



    onButtonCloseWindow() {
        this.node.active = false;
    }

    onBtnOpenChooseDetail(){
        console.log("打开选择框详情");

        console.log("Core.Instance.currentView",Core.Instance.currentView)
        if(Core.Instance.currentView === EView.MartialView){ 
            this.node.parent.parent.parent.getChildByName("ChooseBoard").active = true;
        // 被动武学选择框，选心法武学
        } else if(Core.Instance.currentView === EView.PlayerView){ 
            // 判断人物等级，如果小于5级，不能打开选择框


            console.log("Core.Instance.players.get(Core.Instance.currentPlayer).level",Core.Instance.players.get(Core.Instance.currentPlayer).level)
            if(Core.Instance.players.get(Core.Instance.currentPlayer).level < 5){
                Core.Instance.showTips("义士5级解锁心法");
                return;
            }
            this.node.parent.getChildByName("ChooseBoard").active = true;
        }


    }




}


